<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="nav-header">
			<view class="nav-bar">
				<view class="nav-left" @click="goBack">
					<view class="back-arrow"></view>
				</view>
				<view class="nav-title">团购优惠</view>
				<view class="nav-right"></view>
			</view>

			<!-- 占位区域（保持和 navigation.vue 一样的高度） -->
			<view class="search-placeholder"></view>
		</view>

		<!-- 内容区域 -->
		<view class="content-view">
			<scroll-view class="content-scroll" scroll-y>
				<view class="deal-card" v-for="(item, index) in deals" :key="index" @click="goToDetails(item)">
					<!-- 卡片顶部区域 -->
					<view class="card-top">
						<image class="deal-image" :src="item.image" mode="aspectFill"></image>
					</view>
					<!-- 卡片底部区域 -->
					<view class="card-bottom">
						<text class="deal-text">{{ truncateTitle(item.title) }}</text>
						<view class="detail-link">
							<text class="detail-text">详情</text>
							<view class="arrow-icon"></view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';

	// 团购优惠数据
	const deals = ref([{
			id: 1,
			title: '汽车惠民活动走进群众生活',
			image: '/static/image/图层 1@2x.png',
			source: '济源某某汽车行业',
			date: '2023/3/10 11:09',
			description: '哇噻!薅羊毛的看过来!易车修汽车维修服务中心出优惠团购了!纯手工洗车只要25元一次,还增20元油券,够意思了吧!哇噻!薅羊毛的看过来!易车修汽车维修服务中心出优惠团购了!纯手工洗车只要25元一次,还增20元油券,够意思了吧!',
			price: '99.00',
			originalPrice: '199.00',
			startDate: '2023-3-10 08:00',
			endDate: '2023-3-18 23:59',
			phone: '0379-66666666',
			notes: '暂无'
		},
		{
			id: 2,
			title: '汽车惠民活动走进群众生活',
			image: '/static/image/图层 1@2x.png',
			source: '济源某某汽车行业',
			date: '2023/3/10 11:09',
			description: '哇噻!薅羊毛的看过来!易车修汽车维修服务中心出优惠团购了!纯手工洗车只要25元一次,还增20元油券,够意思了吧!哇噻!薅羊毛的看过来!易车修汽车维修服务中心出优惠团购了!纯手工洗车只要25元一次,还增20元油券,够意思了吧!',
			price: '99.00',
			originalPrice: '199.00',
			startDate: '2023-3-10 08:00',
			endDate: '2023-3-18 23:59',
			phone: '0379-66666666',
			notes: '暂无'
		}
	]);

	// 返回
	const goBack = () => {
		uni.navigateBack();
	};

	// 处理菜单点击
	const handleMenu = () => {
		// 菜单功能
	};

	// 处理更多点击
	const handleMore = () => {
		// 更多功能
	};

	// 截断标题，超过8个字显示省略号
	const truncateTitle = (title) => {
		if (!title) return '';
		if (title.length > 8) {
			return title.substring(0, 8) + '......';
		}
		return title;
	};

	// 跳转到详情页
	const goToDetails = (item) => {
		// 将数据编码后传递
		const data = encodeURIComponent(JSON.stringify(item));
		uni.navigateTo({
			url: `/pages/index/groupBuyingDeals/discountDetails/discountDetails?data=${data}`
		});
	};
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #f5f5f5;
		overflow: hidden;
	}

	/* 顶部导航栏 */
	.nav-header {
		background: linear-gradient(180deg, #2477F4 0%, #166BEC 100%);
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}

	.nav-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		padding-top: calc(20rpx + env(safe-area-inset-top));
		position: relative;
	}

	.nav-left {
		width: 80rpx;
		display: flex;
		align-items: center;
		cursor: pointer;
	}

	.back-arrow {
		width: 24rpx;
		height: 24rpx;
		border-left: 4rpx solid #fff;
		border-bottom: 4rpx solid #fff;
		transform: rotate(45deg);
		margin-left: 10rpx;
	}

	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		font-weight: 500;
		color: #fff;
		position: absolute;
		left: 0;
		right: 0;
		pointer-events: none;
	}

	.nav-right {
		width: 80rpx;
	}

	.icon-circle {
		width: 56rpx;
		height: 56rpx;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.25);
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.three-dots {
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 4rpx;
	}

	.dot {
		width: 5rpx;
		height: 5rpx;
		background: #fff;
		border-radius: 50%;
	}

	.target-icon {
		position: relative;
		width: 28rpx;
		height: 28rpx;
	}

	.outer-circle {
		position: absolute;
		top: 0;
		left: 0;
		width: 28rpx;
		height: 28rpx;
		border: 2rpx solid #fff;
		border-radius: 50%;
	}

	.inner-circle {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 10rpx;
		height: 10rpx;
		background: #fff;
		border-radius: 50%;
	}

	/* 搜索栏占位（保持和 navigation.vue 一样的高度） */
	.search-placeholder {
		height: 250rpx;
	}

	/* 内容视图 */
	.content-view {
		flex: 1;
		padding: 0 30rpx 20rpx 30rpx;
		margin-top: -250rpx;
		height: 0;
		overflow: visible;
		display: flex;
		flex-direction: column;
	}

	.content-scroll {
		flex: 1;
		height: 0;
		width: 100%;
	}

	/* 团购卡片 */
	.deal-card {
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
		margin-bottom: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
	}

	/* 卡片顶部区域 */
	.card-top {
		width: 100%;
		height: 400rpx;
		position: relative;
	}

	.deal-image {
		width: 100%;
		height: 100%;
		border-radius: 12rpx;
	}

	/* 卡片底部区域 */
	.card-bottom {
		background: #fff;
		padding: 30rpx 0 0 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.deal-text {
		font-size: 32rpx;
		color: #000;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		min-width: 0;
	}

	.detail-link {
		display: flex;
		align-items: center;
		gap: 8rpx;
		margin-left: 20rpx;
		flex-shrink: 0;
	}

	.detail-text {
		font-size: 28rpx;
		color: #999;
	}

	.arrow-icon {
		width: 18rpx;
		height: 18rpx;
		border-right: 4rpx solid #999;
		border-top: 4rpx solid #999;
		transform: rotate(45deg);
	}
</style>